// src/store/index.js
import { createStore } from 'vuex';
export default createStore({

  state: {
    // localStorage.getItem('key');
    // userInfo: { userName: '', passWord: '' }
    isLogin: false,
    userInfo: localStorage.getItem('loginData') && JSON.parse(localStorage.getItem('loginData')) || {},
  },

  mutations: {
    setUserInfo(state, uInfo) {
      state.userInfo = uInfo;
    },
    logout(state) {
      state.userInfo = {};
      localStorage.removeItem('loginData');

    }

  },
  getters: {
    // 你可以在这里添加 getter
    userInfo: state => state.userInfo,
    isLogin: state => !!state.userInfo.userName
  },
  actions: {
    // 你可以在这里添加异步操作
  },
})
// export default createStore({
//   state: {
//     activeTab: 'home', // 默认选中的标签页
//     menuItems: [
//       { index: 'home', label: '首页' },
//       { index: 'products', label: '产品' },
//       { index: 'about', label: '关于我们' },
//     ],
//   },
//   mutations: {
//     setActiveTab(state, tab) {
//       state.activeTab = tab;
//     },
//   },
//   actions: {
//     updateActiveTab({ commit }, tab) {
//       commit('setActiveTab', tab);
//     },
//   },
//   getters: {
//     getActiveTab: (state) => state.activeTab,
//     getMenuItems: (state) => state.menuItems,
//   },
// });